﻿using System;using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Windows.Media.Imaging;
namespace 
MySilverlightTest{    
public partial class Control_Combobox : UserControl    {        public Control_Combobox()        {            InitializeComponent();            Loaded += new RoutedEventHandler(Control_Combobox_Loaded);        }        void Control_Combobox_Loaded(object sender, RoutedEventArgs e)        {            this.comboBox.Items.Add("武汉");            this.comboBox.Items.Add("大连");            this.comboBox.Items.Add("苏州");            List<MyData> list = new List<MyData>            {                new MyData{Time =DateTime .Now .AddDays(1),Place="中山路"},                new MyData{Time =DateTime .Now .AddDays(2),Place="光谷高新"}            };            this.comboBox3.DisplayMemberPath = "Place";            this.comboBox3.ItemsSource = list;            ComboBoxItem cbiRight = new ComboBoxItem();            cbiRight.Background = new SolidColorBrush(Colors.Yellow);            cbiRight.HorizontalContentAlignment = HorizontalAlignment.Right;            cbiRight.SetValue(ComboBoxItem.ContentProperty, "上海");            ComboBoxItem cbiCenter = new ComboBoxItem();            cbiCenter.Background = new SolidColorBrush(Colors.Cyan);            cbiCenter.HorizontalContentAlignment = HorizontalAlignment.Center;            cbiCenter.SetValue(ComboBoxItem.ContentProperty, "北京");            ComboBoxItem cbiLeft = new ComboBoxItem();            cbiLeft.Background = new SolidColorBrush(Colors.LightGray);            cbiLeft.HorizontalContentAlignment = HorizontalAlignment.Left;            cbiLeft.SetValue(ComboBoxItem.ContentProperty, "深圳");            this.comboBox1.Items.Add(cbiRight);            this.comboBox1.Items.Add(cbiCenter);            this.comboBox1.Items.Add(cbiLeft);            Image img = new Image();            img.Source = new BitmapImage(new Uri("0.jpg",UriKind .Relative));            Label lbl = new Label();            lbl.Content = "带图片的选项";            StackPanel sp = new StackPanel();            sp.Orientation = Orientation.Horizontal;            sp.Children.Add(img);            sp.Children.Add(lbl);            ComboBoxItem multipleCmb = new ComboBoxItem();            multipleCmb.Content = sp;            this.comboBox2.Items.Add(multipleCmb);                    }        public class MyData        {            public DateTime Time            { get; set; }            public string Place            { get; set; }        }        private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)        {            string selected = comboBox.SelectedValue as string;        }        private void comboBox3_SelectionChanged(object sender, SelectionChangedEventArgs e)        {            MyData md = (sender as ComboBox).SelectedItem as MyData;            DateTime selectedDateTime = md.Time;            string selectedPlace = md.Place;            MyData md2 = comboBox3.SelectedValue as MyData;            DateTime selectedDateTime2 = md2.Time;            string selectedPlace2 = md2.Place;         }    }}